﻿#ifndef MAINDESKTOP_H
#define MAINDESKTOP_H

#include <QWidget>
#include "Monitoring/monitoring.h"
#include "queryServer/queryserver.h"

#include "taskmanager/ess_single.h"
#include "singleProject/single_project.h"

#include "record/dailyrecord.h"


namespace Ui {
class MainDesktop;
}

class MainDesktop : public QWidget
{
    Q_OBJECT

public:
    explicit MainDesktop(QWidget *parent = 0);
    ~MainDesktop();
    bool Desktop=true;
    int TableWidgetcount=0;
    QTimer *DesktopTimer;

//    monitoring *monitoringI;
    dailyRecord *dailyRecordI;      // 日志显示对象

    ServerInit ServerInitItem;      //基础信息
    QDateTime statusTimer;          //超时默认取消选中
    QDateTime statusTimer_agv;      //超时默认取消选中

    void MainDesktopInit();

    QMap<int,email_message>email_messageMap;
    QMap<int, record_log>currentRecord_logMap;

    int taskStatusiKey_count=0;
    QMap<QString,int> taskStatusiKeylist;                   //agvStatusiKey为空时: AGV系统往 MES服务器实时更新 任务的状态信息

    int taskWaitAction=0;                                   //暂存位模式  0启用所有暂存位   1禁用装机暂存位  2禁用下机暂存位  3禁用所有暂存位
    int agvTaskBool=0;                                      //AGV任务启动状态--:  0系统自动 1启动  2暂停
    int taskAgvNum=0;                                       //0 自动分配
    int taskMode=0;                                         //任务模式
    SAPExcelInfo seletSAPExcelInfoI;
    QMap<int, SAPExcelInfo>seletSAPExcelInfoTask;

    QMap<int,QString>CarStautsMap;
    bool currentBatteryLevel=true;
    AGVCurrentTask AGVCurrentTaskI;
    QMap<QString,AGVCurrentTask>AGVCurrentTaskMap;          // 当前AGV状态信息

    void tableWidget_Show();                                // tableWidget 更新显示
    QList<RW_Excel>TableWidget();                           // 任务列表

    void tableWidget_Show_agv();                            // tableWidget 更新显示
    QList<RW_Excel>TableWidget_agv();                       // AGV列表

    void CancelInit(QString taskType);                      // 更新显示

    //******************************* 设备任务状态更新部分*****************************//

    bool setAGVCurrentTaskMap_Status(QMap<QString,AGVCurrentTask>AGVCurrentTaskMap);//更新AGV状态信息


signals:

    void sig_deleteSAPExcelInfoTask(SAPExcelInfo seletSAPExcelInfoI);   //异常删除任务

    void sig_UPSAPExcelInfoTask(SAPExcelInfo seletSAPExcelInfoI);      //更新SAP 任务状态

    //手动更新AGV当前动作指令状态
    void sig_AGVCurrentTaskAction(QString AGVIP,QString Type, int Action);

    void sigAgvTaskBool(int TaskBool);                                 //AGV任务启动状态

    void sig_WriteModbusII(int address, quint16 value);//PLC 监控触发 Modbus 写入

    void sig_UpdateStationI(QString Station, int stationStatus, QString scanCode);//暂存库位界面更新库位状态

    void sig_Translate();//主界面翻译信号

public slots:
    void ON_MainDesktopTimer();

    void SlotsetCurrentItem(int row, int column);

    void SlotsetCurrentItem_2(int row, int column);

    void slotAGVCurrentTaskMap(QMap<QString,AGVCurrentTask>AGVCurrentTaskMapI,bool BatteryLevel);

    void ON_Click();

    void ON_WriteModbusI(int address, quint16 value);//PLC 监控触发 Modbus 写入

    void ON_UpdateStation(QString Station, int stationStatus, QString scanCode);//暂存库位界面更新库位状态

    void ON_Translate();//主界面翻译信号

    void ON_TextDisplay(QString Text);//提示文本描述显示

private slots:

    void on_Delete_Button_clicked();

    void on_taskStatusBox_AGV_currentTextChanged(const QString &arg1);

    void on_Button_Init_clicked();

    void on_AgvExecute_re_clicked();

    void on_taskStatusBox_ESS_currentIndexChanged(int index);

    void on_AgvExecute_re_2_clicked();

private:
    Ui::MainDesktop *ui;
    QPushButton *currentlabel;
};

#endif // MAINDESKTOP_H
